from django.conf import settings
from django.db import transaction
from rest_framework import viewsets
from rest_framework import serializers
from rest_framework.serializers import *
from rest_framework.response import Response
from rest_framework.validators import UniqueValidator, UniqueTogetherValidator  # 验证器

from iClouds.apidev import filter_views
from iClouds.Permissions import (
    OR,
    AllPermissions,
    MyPermissions,
    BoxPermissions,
    WeChatPermissions,
)
from iClouds.Authentication import (
    MyJWTAuthentication,
    BoxJWTAuthentication,
    WeChatJWTAuthentication,
)
from mysqldb import redis as REDIS
from mysqldb.models import *

from .FilterBackends import *

import random
import time


class NoneSerializer(serializers.Serializer):
    """无请求参数"""

    class Meta:
        fields = "__all__"


class HasWorkSerializer(serializers.Serializer):
    """查询场所上机数据"""

    barid = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=255,
        required=True,
        help_text="场所编码",
    )
    types = ChoiceField(
        choices=[("taq", "营业端"), ("tap", "数据看板"), ("map", "机位图")],
        help_text="场景类型(taq 营业端,tap 数据看板,map 机位图)",
    )

    class Meta:
        fields = "__all__"


class HasWorkMemberListSerializer(serializers.Serializer):
    """查询会员记录"""

    barid = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=255,
        required=True,
        help_text="场所编码",
    )
    host = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=255,
        required=True,
        help_text="场所机号",
    )

    class Meta:
        fields = "__all__"


class MoniterUpdateWorkingStateSerializer(serializers.Serializer):
    """修改终端状态"""

    barid = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=255,
        required=True,
        help_text="场所编码",
    )
    host = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=255,
        required=True,
        help_text="机器编号",
    )
    status = ChoiceField(
        choices=[("0", "维修"), ("2", "待打扫"), ("3", "待机")], help_text="终端状态"
    )

    class Meta:
        fields = "__all__"


class MoniterOnlineWorkingStateSerializer(serializers.Serializer):
    """终端上机状态"""

    class Meta:
        fields = "__all__"

    barid = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=255,
        required=True,
        help_text="场所编码",
    )
    host = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=255,
        required=True,
        help_text="机器编号",
    )
    vhash = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=255,
        required=True,
        help_text="会员识别码",
    )


class MoniterUpdateWorkingEventSerializer(serializers.Serializer):
    """推送事件"""

    barid = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=255,
        required=True,
        help_text="场所编码",
    )
    host = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=255,
        required=True,
        help_text="机器编号",
    )
    status = ChoiceField(
        choices=[
            ("0", "维修"),
            ("1", "会员上机"),
            ("2", "待打扫"),
            ("3", "待机"),
            ("4", "健康提醒"),
            ("5", "呼叫提醒"),
            ("6", "点赞打赏"),
            ("7", "游戏上线"),
            ("8", "员工在岗离岗"),
            ("9", "工作项提交"),
        ],
        help_text="事件状态",
    )
    name = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=255,
        required=False,
        help_text="消息主键",
    )
    message = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=255,
        required=False,
        help_text="消息内容",
    )

    class Meta:
        fields = "__all__"


class MoniterUpdateGamesStateSerializer(serializers.Serializer):
    """游戏上报"""

    barid = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=255,
        required=True,
        help_text="场所编码",
    )
    host = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=255,
        required=True,
        help_text="机器编号",
    )
    name = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=255,
        required=True,
        help_text="游戏名称",
    )
    status = ChoiceField(choices=[(1, "运行"), (0, "停止")], help_text="游戏状态")

    class Meta:
        fields = "__all__"


class TestSendMessageNoneSerializer(serializers.Serializer):
    """无序列化"""

    status = ChoiceField(
        choices=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], help_text="消息类型"
    )
    localhost = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=255,
        help_text="机器编号",
    )
    group = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=255,
        required=False,
        help_text="机器区域",
    )
    ipaddr = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=255,
        required=False,
        help_text="机器IP",
    )
    currenttime = DateTimeField(
        allow_null=True,
        required=False,
        help_text="当前时间",
    )
    gender = IntegerField(
        max_value=1,
        min_value=0,
        required=False,
        help_text="性别",
    )
    level = IntegerField(
        max_value=1,
        min_value=0,
        required=False,
        help_text="会员级别",
    )
    games = ListField(
        child=CharField(),
        required=False,
        help_text="游戏列表",
    )

    class Meta:
        fields = "__all__"
